DropDown.inherit("Control");

function DropDown(node){
    this.Control(node);
    
	this.submitState=this.properties.getString("submitState");
	this.selectForm=document.getElementById(this.properties.getString("id"));
	
	this.extractHandlerBody=function (handler) {
		if (handler instanceof Function){
			return handler.getBody();
		}
	}	
		
	if (this.properties.getString("autoPostBack")){
		var handler=this.extractHandlerBody(this.selectForm.onchange);
		this.onchange=new Function("if (this.onBeforePostBack()) {" + handler+ ";} else this.setValue(this.currentValue);");
		this.selectForm.onchange=null;
		this.getEventHandler().registerListener("change", this);

		handler=this.extractHandlerBody(this.selectForm.onfocus);
		this.onfocus=new Function(handler+"; this.currentValue=this.getValue();");
		this.selectForm.onfocus=null;
		this.getEventHandler().registerListener("focus", this);		
	}
    
}

//This method may be overriden to control postBack processing.
//It should return true if postBack is allowed,
//otherwise, postback will be cancelled, and previous 
//select value will be set.
DropDown.prototype.onBeforePostBack=function () {
	return true;
}

DropDown.prototype.getEventHandler=function () {
		if (!this.eventHandler){
			this.eventHandler=new EventHandler(this, this.selectForm);
		}
		return this.eventHandler;
}
	
	
DropDown.prototype.toString=function () {
	return this.submitState;

//		if (this.selectForm.selectedIndex>-1) {
//			return this.selectForm.options[this.selectForm.selectedIndex].text;
//		}
//		return "";
}
		
DropDown.prototype.clear=function () {
		if (!this.selectForm.disabled) {
			this.selectForm.selectedIndex=0;
		}
}

DropDown.prototype.getIndex=function () {
		return this.selectForm.selectedIndex;
}
	
DropDown.prototype.getValue=function () {
		if (this.selectForm.selectedIndex>-1) {
			return this.selectForm.options[this.selectForm.selectedIndex].value;
		}
		return "";
	}
	
DropDown.prototype.setValue=function (value) {
		this.selectForm.value=value;
}	
	
DropDown.prototype.populatePopupParameters=function (prefix, parameters) {
		parameters.add(prefix+".id", this.getValue());	
}



